package com.example.demo.start;

public class ThreadStop implements Runnable {

    private boolean flag = true;

    @Override
    public void run() {
        while (flag){
            int  i = 0;
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程运行中·····" + i++);
        }
    }

    private void  stopThread(){
        this.flag = false;
    }
    public static void main(String[] args) {
        ThreadStop threadStop = new ThreadStop();
        new Thread(threadStop).start();


        for (int i = 0; i < 1000; i++) {
            System.out.println("主线程·······" + i);
            if (i == 900){
               threadStop.stopThread();
               System.out.println("线程停止了");
           }
        }
    }
}
